<?php require_once('../../Connections/cotiza.php'); ?>
<?php 
$tipo  = $_GET['tipo'];
$part  = $_GET['pt'];
$solic = $_GET['s_id'];
$capa  = $_GET['capa'];
$pct_c = $_GET['pct_c'];
$pct   = $_GET['pct'];
$fila  = $_GET['fila'];
//$pos   = $_GET['pos'];

mysql_select_db($database_cotiza, $cotiza);

if($tipo == "part")
{
	if($pct <> "")
		$query = "INSERT INTO 			receta_det(receta_pt_id,receta_solic_id,receta_capa,receta_pct,receta_pct_capa,receta_item,receta_fila) 
			  VALUES('$part','$solic',$capa,$pct,$pct_c,1,$fila)
			  ON DUPLICATE KEY UPDATE receta_pct = $pct, receta_pct_capa = $pct_c";
	else
		$query = "DELETE FROM receta_det 
						WHERE receta_pt_id = '$part' 
						  AND receta_solic_id = '$solic'
						  AND receta_capa = $capa";
					  
}//if($tipo == "part")

if($tipo == "id_part")
{
	if($part <> "")
	{
		$query = "SELECT * FROM receta_det 
		                 WHERE receta_solic_id = '$solic' 
						   AND receta_fila     = $fila";
		$rslt_fila = mysql_query($query,$cotiza) or die(mysql_error());
		$num_fila  = mysql_num_rows($rslt_fila);
		
		if($num_fila >=1)
		{
			$query = "UPDATE receta_det
						 SET receta_pt_id = '$part'
					   WHERE receta_fila  = $fila
						 AND receta_solic_id = '$solic'";
		}//if($num_fila >=1)
	}
	else
		$query = "DELETE FROM receta_det 
						WHERE receta_fila = '$fila'
						  AND receta_solic_id = '$solic'";
	$pct_c = 1;
}//if($tipo == "part")

if($tipo == "capa")
{
	if($pct_c <> "")
		$query = "UPDATE receta_det SET receta_pct_capa = $pct_c WHERE receta_capa = $capa";
	/*else
		$query = "DELETE FROM receta_det 
						WHERE receta_pt_id = '$part' 
						  AND receta_solic_id = '$solic'
						  AND receta_capa = $capa";*/
}
echo $query;

if($pct_c > 0)
	mysql_query($query,$cotiza) or die(mysql_error());
?>

<?php 
mysql_close($cotiza);
?>